home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-09 | 3.1 KB | 98 lines | [TEXT/CWIE] |
- // Simple framework for Macintosh sample code
- // This file contains the trap detection related code code for the framework.
- //
- // 9/16/94 david first cut
- // 9/20/95 david improved comments
-
- #include <Types.h>
- #include <Traps.h>
- #include <Patches.h>
- #include <OSUtils.h>
- #include <Gestalt.h>
-
- #include "trapUtils.h"
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTION PROTOTYPES
- |**| ==============================================================================
- \**/
- short NumToolboxTraps ( void ) ;
- TrapType GetTrapType ( short theTrap ) ;
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- TrapAvailable
- *------------------------------------------------------------------------------*
- This function determines a traps is available on the user machine.
- This function should only be used in cases where that Gestalt Manager
- cannot be used to determine if a function is available. (For example,
- there is no way to detimine if the _Gestalt or _WaitNextEvent traps are
- available by calling Gestalt )
- \*------------------------------------------------------------------------------*/
- Boolean TrapAvailable ( short theTrap )
- {
- TrapType tType;
- Boolean isAvail;
-
- tType = GetTrapType(theTrap) ;
- if (tType == kToolboxTrapType)
- {
- theTrap &= 0x07FF;
- if (theTrap >= NumToolboxTraps() )
- theTrap = _Unimplemented ;
- }
-
- isAvail = NGetTrapAddress(theTrap, tType) !=
- GetToolboxTrapAddress(_Unimplemented) ;
- return isAvail;
- }
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- NumToolboxTraps
- *------------------------------------------------------------------------------*
- This function determines the number of toolbox traps (0x0200 or 0x0400).
- This function relies on the fact the _InitGraf trap (0xA86E) is always
- implimented. If the trap dispatch table has more than 0x0200 entries
- then 0xAA6E is either unimplimented or not the same as the trap address
- of _InitGraf
- \*------------------------------------------------------------------------------*/
- static short NumToolboxTraps ( void )
- {
- if (GetToolboxTrapAddress(_InitGraf) == GetToolboxTrapAddress(0xAA6E))
- return 0x0200 ;
- else
- return 0x0400 ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- GetTrapType
- *------------------------------------------------------------------------------*
- This function determines the type of trap (toolbox or os ).
- \*------------------------------------------------------------------------------*/
- static TrapType GetTrapType ( short theTrap )
- {
- if ((theTrap & 0x0800) > 0)
- return kToolboxTrapType ;
- else
- return kOSTrapType ;
- }
-
-